/*
 * @Author: Endlessdelete 1119229550@qq.com
 * @Date: 2022-05-06 09:40:54
 * @LastEditors: Endlessdelete 1119229550@qq.com
 * @LastEditTime: 2022-05-06 17:59:41
 * @FilePath: \RVMDK（uv5）d:\Embedded development reference\GD32\工程代码\Key_Interrupt\User\BSP\bsp_key.c
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include "bsp_key.h"


uint8_t keyflag = 0;

//key1=pc0 key2=pc1 key3=pc2
void Key_Init(void)
{
    rcu_periph_clock_enable(RCU_GPIOC);//
    gpio_init(GPIOC, GPIO_MODE_IPU, GPIO_OSPEED_50MHZ, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2);//上拉输入
}
void Key_Interrupt_Init(void)
{
    Key_Init();
        /* enable the AF clock */
    rcu_periph_clock_enable(RCU_AF);
    /* enable and set key EXTI interrupt to the specified priority */
    nvic_priority_group_set(NVIC_PRIGROUP_PRE2_SUB2);
    nvic_irq_enable(EXTI0_IRQn, 2U, 2U);
    nvic_irq_enable(EXTI1_IRQn, 2U, 2U);
    nvic_irq_enable(EXTI2_IRQn, 2U, 2U);

    /* connect key EXTI line to key GPIO pin */
    gpio_exti_source_select(GPIO_PORT_SOURCE_GPIOC, GPIO_PIN_SOURCE_0);
    gpio_exti_source_select(GPIO_PORT_SOURCE_GPIOC, GPIO_PIN_SOURCE_1);
    gpio_exti_source_select(GPIO_PORT_SOURCE_GPIOC, GPIO_PIN_SOURCE_2);

    /* configure key EXTI line */
    exti_init(EXTI_0, EXTI_INTERRUPT, EXTI_TRIG_FALLING);//中断模式，下降沿触发
    exti_init(EXTI_1, EXTI_INTERRUPT, EXTI_TRIG_FALLING); //中断模式，下降沿触发
    exti_init(EXTI_2, EXTI_INTERRUPT, EXTI_TRIG_FALLING); //中断模式，下降沿触发

    exti_interrupt_flag_clear(EXTI_0);
    exti_interrupt_flag_clear(EXTI_1);
    exti_interrupt_flag_clear(EXTI_2);
}

